package com.newasia.management.controller;/**
 * Created by mic on 2019/8/1.
 */

import com.newasia.commons.result.ResponseData;
import com.newasia.commons.result.ResponseUtil;
import com.newasia.management.IManagementBrandService;
import com.newasia.management.constants.ManagementRetCode;
import com.newasia.management.dto.productBrand.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * lyh
 * 2019/10/24
 */
@Slf4j
@RestController
@RequestMapping("/management")
public class BrandController {

    @Reference(timeout = 3000)
    IManagementBrandService managementBrandService;


    /**品牌**/
    /**增*/
    @PostMapping("/brand")
    public ResponseData createBrand(@RequestBody CreateBrandRequest request, HttpServletRequest httpServletRequest){

        CreateBrandResponse response= managementBrandService.createBrand(request);

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);
    }

    /**删*/
    @DeleteMapping("/brand/{brandId}")
    public ResponseData deleteBrand(@PathVariable("brandId") Long brandId, HttpServletRequest httpServletRequest){

        DeleteBrandResponse response= managementBrandService.deleteBrand(brandId);

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);
    }


    /**改*/
    @PutMapping("/brand/{brandId}")
    public ResponseData changeBrand(@PathVariable("brandId") Long brandId, @RequestBody ChangeBrandRequest request, HttpServletRequest httpServletRequest){

        ChangeBrandResponse response= managementBrandService.changeBrand(brandId,request);


        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);

    }

    /**查*/
    @GetMapping("/brand")
    public ResponseData brand(String key, HttpServletRequest httpServletRequest){
        GetBrandResponse response= managementBrandService.getBrandList(key);

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);

    }





}
